﻿using System;

namespace LeastSquaresSolver
{
    class Program
    {
        static void Main(string[] args)
        {
            var points = new[]
            {
                new Point { X = 1, Y = 10 },
                new Point { X = 2, Y = 20 },
                new Point { X = 3, Y = 30 },
                new Point { X = 4, Y = 40 },
                new Point { X = 5, Y = 50 },
                new Point { X = 6, Y = 60 }
            };
            var solver = new LeastSquares(points);
            bool again = true;
            while (again)
            {
                Console.WriteLine();
                Console.WriteLine("Provide a value for x");
                var x = decimal.Parse(Console.ReadLine());
                var y = solver.Solve(x);
                Console.WriteLine("x = {0}, y = {1} (M = {2}, C = {3})", x, y, solver.M.ToString("N4"), solver.C.ToString("N0"));
                Console.WriteLine("Again? (y/n)");
                again = Console.ReadKey().KeyChar == 'y';
            }
        }
    }
}